//
// Created by 原帅 on 2022/10/16.
//

#include "TestReeAcceptProc.h"
#include "RRepos.h"
#include "RAcceptor.h"
#include "RLog.h"
#include "map"
#include "Ree.h"
#include "TestReeProc.h"

int TestReeAcceptProc::eventProcess(const int fd,const ReeProcType type, const int exdata) {
    if (RRepos<int,RAcceptor>::Inst().getRepos().count(fd)==0)
    {
        RLogErr("Can not find Acceptor info")
        return 0;
    }
    RAcceptor& acceptor = RRepos<int,RAcceptor>::Inst().getRepos().at(fd);

    if (acceptor.getSockfd() == fd)
    {
        RLinkInfo rLinkInfo = acceptor.doAccept();
        RRepos<int,RLinkInfo>::Inst().getRepos().insert(std::pair<int ,RLinkInfo>(rLinkInfo.getFd(),rLinkInfo));
        RLogDbg("incoming a new connection: fd=%d",rLinkInfo.getFd());
        Ree::Inst().addResponder(rLinkInfo.getFd(), READ_FD, new TestReeProc());
    }
    return 0;
}

int TestReeAcceptProc::eventFail(const int fd,const ReeProcType type, const int exdata) {
    return 0;
}
